
*****Open Dataset
use "replication_conjoint_final_Kenya.dta", clear



***Generate Kenya subpanel for Figure 1: Overall acceptance levels

hist like, percent xlabel(1 "1 = Low" 2 3 4 5 6 7 "7 = High") scheme(plotplain) xtitle("Acceptance") ytitle("Percentage of Respondents - Kenya") discrete aspectratio(1) name(graph2, replace)

***Conjoint results for Kenya - Figure 3 and column 3 in Table 2

reg accept i.female i.age i.education i.income i.ethnicity i.reason, cluster(respondent)


estimate store no
local n_no = e(N)

foreach x of numlist 0(1)1 {
lincom  `x'.female 
mat    coef = r(estimate) , r(se)
matrix rownames coef = 	"`x'.female"
matrix resmat = nullmat(resmat) \ coef
}

foreach x of numlist 1(1)4 {
lincom  `x'.age
mat    coef = r(estimate) , r(se)
matrix rownames coef = 	"`x'.age"
matrix resmat = nullmat(resmat) \ coef
}

foreach x of numlist 1(1)6 {
lincom  `x'.education 
mat    coef = r(estimate) , r(se)
matrix rownames coef = 	"`x'.education"
matrix resmat = nullmat(resmat) \ coef
}

*income
foreach x of numlist 1(1)4 {
lincom  `x'.income 
mat    coef = r(estimate) , r(se)
matrix rownames coef = 	"`x'.income"
matrix resmat = nullmat(resmat) \ coef
}

* ethnicity

foreach x of numlist 1(1)5 {
lincom  `x'.ethnicity
mat    coef = r(estimate) , r(se)
matrix rownames coef = 	"`x'.ethnicity"
matrix resmat = nullmat(resmat) \ coef
}

*reason
foreach x of numlist 1(1)5 {
lincom  `x'.reason 
mat    coef = r(estimate) , r(se)
matrix rownames coef = 	"`x'.reason"
matrix resmat = nullmat(resmat) \ coef
}

mat2txt , matrix(resmat) saving("migrant_choice_Kenya.txt") replace
matrix drop resmat

**Create Figure 3:
clear
set more off
insheet using "migrant_choice_Kenya.txt", clear


gen varname=_n
replace varname = 24 in 26
replace varname = 25 in 24
replace varname = 26 in 25
list

#delimit;
label define varlab 
1"Male" 2 "Female" 3 "18-25 years"
4 "34-48 years" 5 "52-65 years" 6 "Above 70"
7 "No formal education" 8 "Primary school"
9 "Secondary school" 10 "Tertiary school" 11 "Technical school"
12 "University degree" 13 "Very low" 14 "Low"
15 "Sufficient" 16 "High"
17  "Kalenjin" 18 "Kamba" 
19 "Kikuyu" 20 "Luhya" 21 "Luo" 
22 "Persecution" 23 "Family reunification" 
25 "Storm/flood" 26 "Drought" 24 "Economic opportunities";
#delimit cr
label values varname varlab
*list

gen group=_n
replace group = 24 in 26
replace group = 25 in 24
replace group = 26 in 25

#delimit;
label define groupings 
1" " 2 "{bf:Gender}" 3 " " 4 " " 5 " " 6 "{bf:Age}" 7 " " 8 " " 9 " " 10 " " 11 " " 12 "{bf:Education}"
13 " " 14 " " 15 " " 16 "{bf:Income}" 17 " " 18 " " 19 " " 20 " " 21 "{bf:Ethnicity}" 22" " 23 " " 24 " " 25 " " 26 "{bf:Reason}";
#delimit cr
label values group groupings
 
gen clo=c1-1.96*c2
gen chi=c1+1.96*c2
*list

*edit

#delimit;
twoway (rspike clo chi varname, lcolor(black) lpattern(shortdash) horizontal ytitle("") yaxis(1) ylabel(1(1)26,valuelabel angle(0)) xlabel(-0.4(0.1)0.2, format(%3.2f)) xtitle("Change in the Probability of Accepting Migrant in City") 
xline(0, lcolor(black))) ||  (scatter group c1, ytitle("", axis(2)) ylabel(1(1)26, valuelabel axis(2)) yaxis(2) mcolor(black) msymbol(smcircle) msize(small) ytitle("")), yline(2.5, lpattern(solid) lcolor(black) extend) yline(6.5, lpattern(solid) lcolor(black) extend) yline(12.5, lpattern(solid) lcolor(black) extend) yline(16.5, lpattern(solid) lcolor(black) extend) yline(21.5, lpattern(solid) lcolor(black) extend) legend(off) scheme(plotplain) aspectratio(1);
#delimit cr


******Rating variable as dependent variable - SI Figure 32 and and column 4 in Table 2


use "replication_conjoint_final_Kenya.dta", clear

reg like i.female i.age i.education i.income i.ethnicity i.reason, cluster(respondent)

estimate store no
local n_no = e(N)

foreach x of numlist 0(1)1 {
lincom  `x'.female 
mat    coef = r(estimate) , r(se)
matrix rownames coef = 	"`x'.female"
matrix resmat = nullmat(resmat) \ coef
}

foreach x of numlist 1(1)4 {
lincom  `x'.age
mat    coef = r(estimate) , r(se)
matrix rownames coef = 	"`x'.age"
matrix resmat = nullmat(resmat) \ coef
}

foreach x of numlist 1(1)6 {
lincom  `x'.education 
mat    coef = r(estimate) , r(se)
matrix rownames coef = 	"`x'.education"
matrix resmat = nullmat(resmat) \ coef
}

*income
foreach x of numlist 1(1)4 {
lincom  `x'.income 
mat    coef = r(estimate) , r(se)
matrix rownames coef = 	"`x'.income"
matrix resmat = nullmat(resmat) \ coef
}

* ethnicity

foreach x of numlist 1(1)5 {
lincom  `x'.ethnicity
mat    coef = r(estimate) , r(se)
matrix rownames coef = 	"`x'.ethnicity"
matrix resmat = nullmat(resmat) \ coef
}

*reason
foreach x of numlist 1(1)5 {
lincom  `x'.reason 
mat    coef = r(estimate) , r(se)
matrix rownames coef = 	"`x'.reason"
matrix resmat = nullmat(resmat) \ coef
}

mat2txt , matrix(resmat) saving("migrant_rating_Kenya.txt") replace
matrix drop resmat

**Create Figure SI 32
clear
set more off
insheet using "migrant_rating_Kenya.txt",  clear

gen varname=_n
replace varname = 24 in 26
replace varname = 25 in 24
replace varname = 26 in 25
list

#delimit;
label define varlab 
1"Male" 2 "Female" 3 "18-25 years"
4 "34-48 years" 5 "52-65 years" 6 "Above 70"
7 "No formal education" 8 "Primary school"
9 "Secondary school" 10 "Tertiary school" 11 "Technical school"
12 "University degree" 13 "Very low" 14 "Low"
15 "Sufficient" 16 "High"
17  "Kalenjin" 18 "Kamba" 
19 "Kikuyu" 20 "Luhya" 21 "Luo" 
22 "Persecution" 23 "Family reunification" 
25 "Storm/flood" 26 "Drought" 24 "Economic opportunities";
#delimit cr
label values varname varlab
*list

gen group=_n
replace group = 24 in 26
replace group = 25 in 24
replace group = 26 in 25

#delimit;
label define groupings 
1" " 2 "{bf:Gender}" 3 " " 4 " " 5 " " 6 "{bf:Age}" 7 " " 8 " " 9 " " 10 " " 11 " " 12 "{bf:Education}"
13 " " 14 " " 15 " " 16 "{bf:Income}" 17 " " 18 " " 19 " " 20 " " 21 "{bf:Ethnicity}" 22" " 23 " " 24 " " 25 " " 26 "{bf:Reason}";
#delimit cr
label values group groupings
 
gen clo=c1-1.96*c2
gen chi=c1+1.96*c2

#delimit;
twoway (rspike clo chi varname, lcolor(black) lpattern(shortdash) horizontal ytitle("") yaxis(1) ylabel(1(1)26,valuelabel angle(0)) xlabel(-1.5(0.5)1, format(%3.2f)) xtitle("Change in the Approval Rating of Migrant in City") 
xline(0, lcolor(black))) ||  (scatter group c1, ytitle("", axis(2)) ylabel(1(1)26, valuelabel axis(2)) yaxis(2)  mcolor(black) msymbol(smcircle) msize(small) ytitle("")), yline(2.5, lpattern(solid) lcolor(black) extend) yline(6.5, lpattern(solid) lcolor(black) extend) yline(12.5, lpattern(solid) lcolor(black) extend) yline(16.5, lpattern(solid) lcolor(black) extend) yline(21.5, lpattern(solid) lcolor(black) extend) legend(off) scheme(plotplain) aspectratio(1);
#delimit cr



